package com.jason.kotlin.core

import com.jason.kotlin.api.HttpConstant
import com.jason.library.network.stetho.NetworkInterceptor
import com.jason.library.network.stetho.NetworkListener
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class RetrofitManager {

    companion object{
        fun <T> getService(service: Class<T>) : T{

            var client = OkHttpClient.Builder()
                //自定义拦截器用于日志输出
                .addInterceptor(LogInterceptor())
                .eventListenerFactory(NetworkListener.get())
                .addNetworkInterceptor(NetworkInterceptor())
                .build()

            val retrofit = Retrofit.Builder().baseUrl(HttpConstant.HOST_URL)
                //格式转换
                .addConverterFactory(GsonConverterFactory.create())
                //.addCallAdapterFactory()
                .client(client)
                .build()
            return retrofit.create(service)

        }


        /*fun apiService(): ApiService {
            return getService(ApiService::class.java)
        }*/
    }


}